package com.lzh.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzh.mapper.TeacherMapper;
import com.lzh.pojo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author reborn
 * @create 2020/5/18-23:56
 */
@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public Teacher selectTeacherZh(String zh, String pwd) {
        return teacherMapper.selectTeacherZh(zh,pwd);
    }

    @Override
    public Teacher selectTeacherById(int id) {
        return teacherMapper.selectTeacherById(id);
    }

    @Override
    public PageInfo<Teacher> selectTeaByName(Integer pageNum, Integer pageSize, String name) {
       PageHelper.startPage(pageNum,pageSize);
        List<Teacher> teacher = teacherMapper.selectTeaByName(name);
        PageInfo pageInfo=new PageInfo<>(teacher);
        return pageInfo;
    }

    @Override
    public int insertTea(Teacher teacher) {
        return teacherMapper.insertTea(teacher);
    }

    @Override
    public Teacher selectZh(String zh) {
        return teacherMapper.selectZh(zh);
    }

//    删除教师
    @Override
    public int deleteTea(int id) {
        return teacherMapper.deleteTea(id);
    }



    //    查询全部教师
    @Override
    public PageInfo<Teacher> selectTeachers(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Teacher> teachers = teacherMapper.selectTeachers();
        PageInfo pageInfo = new PageInfo<>(teachers);
        return pageInfo;
    }


    @Override
    public PageInfo<Teacher> selectPerms(Integer pageNum, Integer pageSize, String perms) {
        PageHelper.startPage(pageNum,pageSize);
        List<Teacher> teachers = teacherMapper.selectPerms(perms);
        PageInfo pageInfo = new PageInfo<>(teachers);
        return pageInfo;
    }

    @Override
    public List<Teacher> selectTeachers() {
        return teacherMapper.selectTeachers();
    }


    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherMapper.updateTeacher(teacher);
    }

    // 根据ids查询教师
    @Override
    public PageInfo<Teacher> selectTeacherByIds(Integer pageNum, Integer pageSize, Set<Integer> ids) {
        PageHelper.startPage(pageNum,pageSize);
        List<Teacher> teachers = teacherMapper.selectTeacherByIds(ids);
        PageInfo pageInfo=new PageInfo<>(teachers);
        return pageInfo;
    }
}
